import 'package:bloc/bloc.dart';
import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.home.learning.spaced_repetitions/unspecified_lexical_item_exposed_card/domain/use_cases/pronounce_lexical_item/use_case.dart';
import 'package:mobile_app.home.learning.spaced_repetitions/unspecified_lexical_item_exposed_card/domain/use_cases/pronounce_lexical_item_use_case/use_case.dart';

part 'bloc_state.dart';

class UnspecifiedLexicalItemExposedCardBloc
    extends Cubit<UnspecifiedLexicalItemExposedCardBlocState> {
  UnspecifiedLexicalItemExposedCardBloc({
    required LexicalItem lexicalItem,
    required PronounceLexicalItem pronounceLexicalItem,
    required PronounceLexicalItemUseCase pronounceLexicalItemUseCase,
  })  : _pronounceLexicalItem = pronounceLexicalItem,
        _pronounceLexicalItemUseCase = pronounceLexicalItemUseCase,
        super(_getInitialState(
          lexicalItem: lexicalItem,
        ));

  static UnspecifiedLexicalItemExposedCardBlocState _getInitialState({
    required LexicalItem lexicalItem,
  }) {
    return UnspecifiedLexicalItemExposedCardBlocState(
      lexicalItem: lexicalItem,
    );
  }

  final PronounceLexicalItem _pronounceLexicalItem;
  final PronounceLexicalItemUseCase _pronounceLexicalItemUseCase;

  void updateLexicalItem({
    required LexicalItem lexicalItem,
  }) {
    emit(state.copyWith(
      lexicalItem: () => lexicalItem,
    ));
  }

  void requestLexicalItemPronunciation() {
    _pronounceLexicalItem(
      lexicalItemTitle: state.lexicalItem.title,
    );
  }

  void requestLexicalItemUseCasePronunciation({
    required LexicalItemUseCase lexicalItemUseCase,
  }) {
    _pronounceLexicalItemUseCase(
      lexicalItemUseCase: lexicalItemUseCase,
    );
  }
}
